import { computed } from '@vue/composition-api'
import { mapState } from 'vuex'
// import { useStore } from 'vuex'
import store from '../store'

export function useState(mapper) {
  const storeStateFns = mapState(mapper)
  const storeState = {}
  Object.keys(storeStateFns).forEach(fnKey => {
    const fn = storeStateFns[fnKey].bind({ $store: store })
    storeState[fnKey] = computed(fn)
  })
  return storeState
}
